#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'ethereal'
__mtime__ = '2018/8/23'

from flask import Flask

from flask_script import Manager
from flask_sqlalchemy import  SQLAlchemy
import os


class Application(Flask):
    #项目初始化方法 static_folder要设置为空 否则就会走这里 一直找不到静态文件
    def __init__(self,import_name,template_folder = None,root_path=None):
        super(Application,self).__init__(import_name,template_folder= template_folder,root_path=root_path,static_folder= None)
        #从py里面加载配置
        self.config.from_pyfile('config/base_setting.py')
        #命令行动态切换配置文件 命令行输入export ops_config=local  然后运行python manage.py runserver
        if "ops_config" in os.environ:
            self.config.from_pyfile('config/%s_setting.py'%os.environ['ops_config'])

        self.config.from_pyfile('config/local_setting.py')
        self.config.from_pyfile('config/production_setting.py')

        db.init_app(self)



db = SQLAlchemy()
#传递自定义的template目录
app = Application(__name__,template_folder=os.getcwd() + "/web/templates/",root_path=os.getcwd())

manage = Manager(app)


#注入模板
from common.libs.UrlManager import UrlManager
app.add_template_global(UrlManager.buildStaticUrl,'buildStaticUrl')
app.add_template_global(UrlManager.buildUrl,'buildUrl')
app.add_template_global(UrlManager.buildImageUrl, 'buildImageUrl')

